package mcsm.DataBaseIntegration;

import java.sql.SQLException;
import java.sql.Statement;

import mcsm.DataBaseInterface.DeleteOperation;

import Stragety.SingleGoodsStragety;

public class DeleteGoodsPreferential implements DeleteOperation {

	private SingleGoodsStragety goodsPreferential;
	private int goodsStraNum;
	
	public DeleteGoodsPreferential(SingleGoodsStragety goodsPreferential) {
		this.goodsPreferential = goodsPreferential;
	}

	@Override
	public Boolean connect(Statement statement) {
		int i = 0; 
		try {
			i = statement.executeUpdate(delete());
			statement.executeUpdate("update number set goodsPreferential = " + goodsStraNum);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return (i != 0);
	}

	@Override
	public String delete() {
		DataBaseConnect database = DataBaseConnect.getDatabase();
		goodsStraNum = database.getSumPreferentialNumber() - 1;
		String id = goodsPreferential.getID();
		String sql = "delete from goodsPreferential where id = " + id;
		return sql;
	}

}
